<!DOCTYPE html>
<html>

<head>
	<title>positionDetail.html</title>

	<meta name="keywords" content="keyword1,keyword2,keyword3">
	<meta name="description" content="this is my page">
	<meta name="content-type" content="text/html; charset=UTF-8">
	<link rel="stylesheet" href="/Hospital/lib/layui-v2.1.6/layui/css/layui.css" media="all">
	<style type="text/css">
		select {
			height: 38px;
			line-height: 1.3;
			line-height: 38px\9;
			border-width: 1px;
			border-style: solid;
			background-color: #fff;
			border-radius: 2px;
			width: 100%;
		}

		.row {
			margin-top: 10px;
		}
	</style>
</head>

<body>
	<div class="layui-form layui-container" style="">
		<div class="layui-row row">
			<div class="layui-col-xs4 layui-col-xs-offset1 layui-col-md2 layui-col-md-offset2">
				<span class="layui-form-label">职位名称: </span>
			</div>
			<div class="layui-col-xs5 layui-col-md2 ">
				<input id="positionName" class="layui-input" type="text" placeholder="不可为空">
			</div>
		</div>

		<div class="layui-row row">
			<div class="layui-col-xs4 layui-col-xs-offset1 layui-col-md2 layui-col-md-offset2">
				<span class="layui-form-label">创建人: </span>
			</div>
			<div class="layui-col-xs5 layui-col-md2">
				<input id="creatorName" class="layui-input" type="text" disabled>
			</div>
		</div>

		<div class="layui-row row">
			<div class="layui-col-xs4 layui-col-xs-offset1 layui-col-md2 layui-col-md-offset2">
				<span class="layui-form-label">职位等级: </span>
			</div>
			<div class="layui-col-xs5 layui-col-md2">
				<select id="rank" name="rank" class="layui-input-inline" lay-filter="sel_rank">
					<option value="1">员工级</option>
					<option value="2">科室级</option>
					<option value="3">门诊级</option>
					<option value="4">总院级</option>
					<option value="5">管理员级</option>
				</select>
			</div>
		</div>

		<div id="div_createTime" class="layui-row row">
			<div class="layui-col-xs4 layui-col-xs-offset1 layui-col-md2 layui-col-md-offset2">
				<span class="layui-form-label">创建时间: </span>
			</div>
			<div class="layui-col-xs5 layui-col-md2">
				<input id="createTime" class="layui-input" type="text" disabled>
			</div>
		</div>

		<div class="layui-row row">
			<div class="layui-col-xs4 layui-col-xs-offset1 layui-col-md2 layui-col-md-offset2">
				<span class="layui-form-label">职位描述: </span>
			</div>
			<div class="layui-col-xs7 layui-col-md5">
				<textarea id="description" class="layui-textarea"></textarea>
			</div>
		</div>

		<div id = "div_permission"class="layui-form-item layui-row row">
			<div class="layui-col-xs4 layui-col-xs-offset1 layui-col-md2 layui-col-md-offset2">
				<span class="layui-form-label">职位权限: </span>
			</div>
			<div class="layui-col-xs7 layui-col-md5" pane="">
				<!-- <input id="1" name="" value="1" disabled="" lay-skin="primary" title="创建员工" type="checkbox"> -->
				<input id="2" name="" value="2" disabled="" lay-skin="primary" title="查询员工" type="checkbox">
				<!-- <input id="3" name="" value="3" disabled="" lay-skin="primary" title="修改员工" type="checkbox"> -->
				<!-- <br /> -->
				<!-- <input id="4" name="" value="4" disabled="" lay-skin="primary" title="创建门诊" type="checkbox"> -->
				<input id="5" name="" value="5" disabled="" lay-skin="primary" title="查询门诊" type="checkbox">
				<!-- <br /> -->
				<!-- <input id="6" name="" value="6" disabled="" lay-skin="primary" title="创建科室" type="checkbox"> -->
				<input id="7" name="" value="7" disabled="" lay-skin="primary" title="查询科室" type="checkbox">
				<!-- <br /> -->
				<!-- <input id="8" name="" value="8" disabled="" lay-skin="primary" title="创建项目" type="checkbox"> -->
				<input id="9" name="" value="9" disabled="" lay-skin="primary" title="查看项目" type="checkbox">
				<!-- <input id="10" name="" value="10" disabled="" lay-skin="primary" title="修改项目" type="checkbox"> -->
				<!-- <br /> -->
				<input id="11" name="" value="11" disabled="" lay-skin="primary" title="创建客户" type="checkbox">
				<input id="12" name="" value="12" disabled="" lay-skin="primary" title="查看客户" type="checkbox">
				<input id="13" name="" value="13" disabled="" lay-skin="primary" title="修改客户" type="checkbox">
				<br />
				<input id="14" name="" value="14" disabled="" lay-skin="primary" title="创建病例" type="checkbox">
				<input id="15" name="" value="15" disabled="" lay-skin="primary" title="查看病例" type="checkbox">
				<input id="16" name="" value="16" disabled="" lay-skin="primary" title="修改病例" type="checkbox">
				<br />
				<!-- <input id="17" name="" value="17" disabled="" lay-skin="primary" title="创建职位" type="checkbox"> -->
				<input id="18" name="" value="18" disabled="" lay-skin="primary" title="查看职位" type="checkbox">
				<!-- <input id="19" name="" value="19" disabled="" lay-skin="primary" title="修改职位" type="checkbox"> -->
				<br />
				<input id="20" name="" value="20" disabled="" lay-skin="primary" title="创建治疗单据(所有)" type="checkbox">
				<input id="21" name="" value="21" disabled="" lay-skin="primary" title="创建治疗单据(个人)" type="checkbox">
				<input id="22" name="" value="22" disabled="" lay-skin="primary" title="查看治疗单据" type="checkbox">
				<input id="23" name="" value="23" disabled="" lay-skin="primary" title="修改治疗单据" type="checkbox">
				<br />
				<input id="24" name="" value="24" disabled="" lay-skin="primary" title="创建费用单据" type="checkbox">
				<input id="25" name="" value="25" disabled="" lay-skin="primary" title="查看费用单据" type="checkbox">
				<input id="26" name="" value="26" disabled="" lay-skin="primary" title="修改费用单据" type="checkbox">
				<br />
				<input id="27" name="" value="27" disabled="" lay-skin="primary" title="查看报表" type="checkbox">
			</div>
		</div>
	</div>
</body>
<script src="/Hospital/lib/jquery.min.js" charset="utf-8"></script>
<script src="/Hospital/lib/layui-v2.1.6/layui/layui.js" charset="utf-8"></script>
<script type="text/javascript">
	

	layui.use('form', function () {
		var form = layui.form;

		initFrame();//初始化表单数据
		rankEvent();//职位权限 监听事件

		//初始化表单数据
		function initFrame() {
			var operator = localStorage.getItem("positionTable_operator");
			if(operator == 1) {
				//新增职位 
				initAddFrame();
			}
			if(operator == 2) {
				//修改职位 
				initAlterFrame();
			}
		}
		
		//修改职位 
		function initAlterFrame() {
			var positionData = JSON.parse(localStorage.getItem("positionDetail"));
			$("#positionName").val(positionData.positionName);
			$("#creatorName").val(positionData.creatorName);
			$("#rank").val(positionData.rankInt);
			$("#description").val(positionData.description);
			$("#createTime").val(positionData.createTime);
			console.log("initFrame.positionData");
			console.log(positionData);
			if(positionData.rankInt == 5) {
				$("#div_permission").hide();
				for (var index = 1;index < 28;index++ ) {
					$("#" + index).attr("checked", "");
				}
				form.render();
			}else {
				//初始化权限
				var permission = positionData.permission;
				for (var index in permission) {
					$("#" + permission[index]).attr("checked", "");
				}
				//开放能够设置权限项目
				$.ajax({
					type: "post",
					url: "/Hospital/permissionController/getPermissionByPositionId",
					data: "",
					success: function (response) {
						console.log(response);
						if (response.code != 200) {
							console.log(response);
							return;
						}
						var pmArray = response.result;
						for (var index in pmArray) {
							$("#" + pmArray[index]).removeAttr("disabled");
						}
						//hideManagerPermission();
						form.render();
					}
				});
			}
		}
		
		//新增职位
		function initAddFrame() {
			var loginUser = JSON.parse(localStorage.getItem("loginUser"));
			$("#creatorName").val(loginUser.employeeName);
			$("#div_createTime").css({"display": "none"});
			for (var index = 1;index < 28;index++) {
				$("#" + index).removeAttr("disabled");
			}
			form.render("checkbox");
		}
		
		//职位等级 监听事件
		function rankEvent() {
			form.on('select(sel_rank)', function(data){
				if(data.value == 5) {
					$("#div_permission").hide();
				}else {
					$("#div_permission").show();
				}
			});  
		}
	});

	function getParam() {
		var positionData = JSON.parse(localStorage.getItem("positionDetail"));
		var permissionIds = [];
		if($("#rank").val() == 5) {
			permissionIds = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27];		
		}else {
			$("input:checkbox:checked").each(function (index, item) {
				permissionIds.push($(this).val());
			});
		}
		//console.log(permissionIds);
		var operator = localStorage.getItem("positionTable_operator");
		var param = {};
		if(operator == 1){
			//如果是新增职位
			//console.log("operator == 1");
			param = {
				permissionIds: JSON.stringify(permissionIds),
				name : $("#positionName").val(),
				rank : $("#rank").val(),
				description : $("#description").val(),
			};
		}
		if(operator == 2){
			//如果是编辑职位
			//console.log("operator == 2");
			param = {
				positionId: positionData.positionId,
				permissionIds: JSON.stringify(permissionIds),
				name : $("#positionName").val(),
				rank : $("#rank").val(),
				description : $("#description").val(),
			};
		}
		
		//console.log("positionDetail.getParam");
		//console.log(param);
		return param;
	}
	
	//将默认是管理员才具有的权限隐藏
	function hideManagerPermission(){
	 	$("#1").attr("disabled","");//创建员工
	 	$("#3").attr("disabled","");//修改员工
		$("#4").attr("disabled","");//创建门诊
		$("#6").attr("disabled","");//创建科室
		$("#8").attr("disabled","");//创建项目
		$("#10").attr("disabled","");//修改项目
		$("#17").attr("disabled","");//创建职位
		$("#19").attr("disabled","");//修改职位 
	}
</script>

</html>